#include<unistd.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(void)
{
	FILE* read_fp;
	char buffer[BUFSIZ + 1];
	int chars_read;
	
	memset(buffer, 0, sizeof(buffer));
	read_fp = popen("ps ax", "r");
	if (NULL != read_fp)
	{
		chars_read = fread(buffer, sizeof(char), BUFSIZ, read_fp);
		while (chars_read > 0)
		{
			buffer[chars_read - 1] = '\0';
			printf("Reading %d-\n %s\n", chars_read, buffer);
			chars_read = fread(buffer, sizeof(char), BUFSIZ, read_fp);
		}
	}
	pclose(read_fp);
	
	return 0;
}